package com.cn.book;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UDPServer {
    public static void main(String[] args) throws IOException {
        //创建通道
        DatagramSocket socket = new DatagramSocket(10010);

        //接受数据
        byte[] bts = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bts, bts.length);
        socket.receive(packet);

        //解析数据
        byte[] data = packet.getData();
        System.out.println(new String(data, 0, packet.getLength()));

        //释放资源
        socket.close();
    }
}
